home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM 1
/
LIGHT-ROM 1 (Amiga Library Services)(1994).iso
/
ffdisks
/
d939.lha
/
ExtraCmds
/
source_etc.lha
/
src
/
SplitName.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
3KB
|
131 lines
/* --------------------------------- -------
* |\ | | | | | |.| | \| |/ /|\ |||||||
* | | | |/ | |\ |/ |/| |\ |/ | ? ---+--- =<
* | | | | | | | | | | | \qqqqqqqqq/
* --------------------------------- ~~~~~~~~~~~~~~~~
* SPLITNAME - Splits a filename into its parts.
* Copyright (C) 1993 Torsten Poulin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* The author can be contacted by s-mail at
* Torsten Poulin
* Banebrinken 99, 2, 77
* DK-2400 Copenhagen NV
* DENMARK
*
* $Id: SplitName.c,v 37.2 93/02/08 14:06:29 Torsten Rel $
* $Log: SplitName.c,v $
* Revision 37.2 93/02/08 14:06:29 Torsten
* Replaced strlen() and rindex() with rlocate() to
* save an additional pass through the name string
* as well as a few bytes ;-)
*
* Fixed a bug in the setting of the EXT variable
* when the name does not contain an extension.
*
* Revision 37.1 93/02/06 18:53:10 Torsten
* This is the initial revision.
*
*/
#include <exec/types.h>
#include <dos/dos.h>
#include <dos/var.h>
#include <dos/dostags.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include "splitname_rev.h"
#define TEMPLATE "NAME/A,PATH,BASE,EXT=EXTENSION"
#define OPT_NAME 0
#define OPT_PATH 1
#define OPT_BASE 2
#define OPT_EXT 3
char const versionID[] = VERSTAG;
char const copyright[] = "$COPYRIGHT: ©1993 Torsten Poulin";
char *rlocate(char *, char);
LONG entrypoint(VOID)
{
struct RDArgs *args;
struct DosLibrary *DOSBase;
struct Library *SysBase;
LONG arg[4];
LONG rc = RETURN_OK;
UBYTE *base, *ext;
SysBase = *(struct Library **) 4L;
if (!(DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37L)))
{
rc = RETURN_FAIL;
goto exit1;
}
arg[OPT_NAME] = arg[OPT_PATH] = arg[OPT_BASE] = arg[OPT_EXT] = 0L;
if (args = ReadArgs(TEMPLATE, arg, NULL))
{
base = FilePart((UBYTE *) arg[OPT_NAME]);
ext = rlocate(base, '.');
if (arg[OPT_EXT])
SetVar((UBYTE *) arg[OPT_EXT], ext ? ext : "", -1, GVF_LOCAL_ONLY);
if (arg[OPT_BASE])
{
/* Truncate *base at start of extension, if applicable */
if(ext)
*ext = '\0';
SetVar((UBYTE *) arg[OPT_BASE], base, -1, GVF_LOCAL_ONLY);
}
if (arg[OPT_PATH])
{
/* Truncate arg[OPT_NAME] at start of basename */
*base = '\0';
SetVar((UBYTE *) arg[OPT_PATH], (UBYTE *) arg[OPT_NAME], -1,
GVF_LOCAL_ONLY);
}
FreeArgs(args);
}
else
{
LONG err = IoErr();
PrintFault(err, "SplitName");
rc = RETURN_ERROR;
}
CloseLibrary((struct Library *) DOSBase);
exit1:
return rc;
}
char *rlocate(char *s, char c)
{
char *pos = NULL;
for (; *s; s++)
if (*s == c)
pos = s;
return pos;
}